package com.hotelmanage.hm.controller;

import com.hotelmanage.hm.service.OrderService;
import com.hotelmanage.hm.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("newOrder")
    public Object newOrder(@RequestBody OrderVO orderVO){
        Map<String,Object> map = new HashMap<String, Object>();


        int result = orderService.newOrder(orderVO);
        if(result==0){
            map.put("status",404);
            map.put("desc","新增失败");
        }else{
            map.put("status",200);
            map.put("desc","新增成功");
        }
        return map;
    }

    @RequestMapping("orders")
    public Object orders(){
        Map<String,Object> map = new HashMap<String, Object>();


        map.put("orders",orderService.getOrders());
        return map;
    }

    @RequestMapping("getOrders")
    public Object getOrders(@RequestParam int userid){
        Map<String,Object> map = new HashMap<String, Object>();


        map.put("orders",orderService.getByUserid(userid));
        return map;
    }

    @RequestMapping("deleteOrder")
    public Object deleteOrder(@RequestParam Integer orderId){
        Map<String,Object> map = new HashMap<String, Object>();


        int result = orderService.deleteOrder(orderId);
        if(result==0){
            map.put("status",404);
            map.put("desc","删除失败");
        }else{
            map.put("status",200);
            map.put("desc","删除成功");
        }
        return map;
    }
}
